/*绑定回车到查询按钮*/
$(function(){
	$(document).keydown(function(){
		if(event.keyCode == 13){ 
		$("#chaxtjrkjl-chaxunanniu").trigger('click'); 
		return false;
		}
	});
});
/*全部、药品、耗材部分切换*/
$(".leixing ul li").click(function () {
	$(this).addClass('xuanzong');
	$(this).siblings('li').removeClass('xuanzong');
	$(this).parent().parent().find('#chaxuntjrkjl-kucunlx').val($(this).val());
	showRukujl();
});

// 业务类型LI点击事件
$('.laiyuan ul li').click(function () {
	$(this).addClass('xuanzong');
	$(this).siblings('li').removeClass('xuanzong');
	$(this).parent().parent().find('#rukujl-yewulx').val($(this).val());
	showRukujl();
});
// 页面显示
function showRukujl() {
	kaishisj = $('#rkjl-kaishjsj').val();
	jieshusj = $('#rkjl-jieshusj').val();
	mingcheng = $('#mingcheng').val();
	gongyingshang = $('#gongyingshang').val();
	kucunlx = $('#chaxuntjrkjl-kucunlx').val();
	if (kucunlx == 2) { kucunlx = '';}
	yewulx = $('#rukujl-yewulx').val();
	if (yewulx == 0) { yewulx = '';}
	getRukujl();	
}
/*获取时间*/
function getShijian(mrkaishisj,mrjieshusj){
	//重置按钮
	$('#chaxtjrkjl-chongzhianniu').click(function(){
		$('#rkjl-kaishjsj').val(mrkaishisj);
		$('#rkjl-jieshusj').val(mrjieshusj);
		$('#mingcheng').val('');
		$('#gongyingshang').val('');
		$('#chaxuntjrkjl-kucunlx').val(2);
		$('#rukujl-yewulx').val(0);
		$('#kucunlxqb').addClass('xuanzong').siblings().removeClass('xuanzong');
		$('#yewulxqb').addClass('xuanzong').siblings().removeClass('xuanzong');	
		//	重置后进行查询
		showRukujl();
	});
};
showRukujl();
/*点击查询按钮*/
$('#chaxtjrkjl-chaxunanniu').click(function(){
	showRukujl();
});
// 获取来来源文字
function getLaiyaunText(num) {
	var laiYuan = null;
	switch (num) {
	case 2: laiYuan = "退费入库";
	break;
	case 3: laiYuan = "库存调整";
	break;
	case 4: laiYuan = "商品入库";
	}
	return laiYuan;
}

/*获取入库记录*/
function getRukujl() {
	var totalNumber = 0;
	var params = {
			'kaishisj': kaishisj,
			'jieshusj': jieshusj,
			'mingcheng': mingcheng,
			'gongyingshang': gongyingshang,
			'yewulx': yewulx,
			'kucunlx': kucunlx
	};
	$.ajax({
		url: path + '/chaxuntjrkjl/getChaxuntjrkjlCount',
		type: 'post',
		data: params,
		async: false,
		success: function (data) {
			if (null != data) {
				totalNumber = data;
			}
			if (totalNumber == 0) {
				$('#chaxtjrkjl-tbneirong').css("display","none");
				$("#chaxtj-rkjl-imp").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
			} else {
				$('#chaxtjrkjl-tbneirong').css("display","block");
				$('#chaxtj-rkjl-imp').html("");
			}
		}
	});
  	var container = $('#pagination-fenyrkjl');
  	container.pagination({
    dataSource:path + '/chaxuntjrkjl/getChaxuntjrkjl?kaishisj='+kaishisj+'&jieshusj='+jieshusj+'&mingcheng='+mingcheng+'&gongyingshang='+gongyingshang+'&yewulx='+yewulx+'&kucunlx='+kucunlx,
    locator: '',
    pageSize: 12,
	showNavigator: true,
    formatNavigator: '共 <%= totalNumber %> 条',
    totalNumber: totalNumber,
    callback: function (data, pagination) {
    	if(data != '') {
			var content = '';
			$(data).each(function(index,e){
				var baozhuangg = this.baozhuanggg || '';
				var shengchancj = this.shengchancj || '';
				var gongyingshang = this.gongyingshang || '';
				var laiyuan = getLaiyaunText(this.yewulx);
				var pici = this.pici || '';
				var jinhuojia = this.jinhuojia;
				var mingcheng = this.bieming || this.mingcheng;
				if (this.jinhuojia == null) {
					jinhuojia = '';
				} else {
					jinhuojia = this.jinhuojia.toFixed(2);
				} 
				index = ((pagination.pageNumber-1)*pagination.pageSize)+index+1;
				content += '<tr id="hang' + this.id+'">'+
				'<td width="7%">' + index + '</td>'+
                '<td width="15%">' + pici + '</td>'+
                '<td width="10%" class="left">' + mingcheng + '</td>'+
                '<td width="10%">' + baozhuangg + '</td>'+
                '<td width="15%">' + shengchancj + '</td>'+
                '<td width="10%">' + gongyingshang + '</td>'+
                '<td width="10%">' + laiyuan + '</td>'+
                '<td width="10%">' + this.shijian + '</td>'+
                '<td width="11%" class="right">' + jinhuojia + '</td>'+
                '<td width="8%">' + this.shuliang + this.danwei + '</td>'+
                '</tr>';
			});
			$('#chaxtj-rkjl-lb').html(content);
    	}
    }
  	});
	if(totalNumber <= 12) {
		$('#pagination-fenyrkjl').css('display','none');
	}else{
		$('#pagination-fenyrkjl').css('display','block');
	}
}